﻿using System;

namespace test1
{
  class test_1
  {
    int num = 9;

    // 乘法表
    public void Multiplication()
    {
      for (int i = 1; i <= num; i++)
      {
        for (int j = 1; j <= i; j++)
        {
          Console.Write(" " + j + "*" + i + "=" + i * j);
        }
        Console.WriteLine("");
      }
    }

    // 输入一个自然数n，输出前n个自然数的阶乘的和
    public void input()
    {
      while (true)
      {
        Console.WriteLine("请输入一个自然数n：(输入p结束)");
        string s = Console.ReadLine();
        if (s == "p")
        {
          Console.WriteLine("程序结束，再见！");
          break;
        }
        int n = int.Parse(s);
        int all = 1;// 0的阶乘为1
        for (int i = 1; i <= n; i++)
        {
          int jj = 1;
          for (int j = 1; j <= i; j++)
          {
            jj *= j;
          }
          all += jj;
        }
        Console.WriteLine("前n个自然数的阶乘的和为：" + all);
      }

    }


    public void Tosort(int[] arr)
    {
      if (arr.Length > 0)
      {
        test_1 test = new test_1();
        test.log("排序前", arr);
        test.sort(arr);
        test.log("排序后", arr);
      }
    }

    // 打印数组
    public void log(string title, int[] a)
    {
      if (a.Length > 0)
      {
        Console.Write(title + "：");
        for (int i = 0; i < a.Length; i++)
        {
          Console.Write(a[i] + " ");
        }
        Console.WriteLine("");
      }
    }

    // 排序
    public void sort(int[] arr)
    {
      for (int i = 0; i < arr.Length; i++)
      {
        for (int j = i + 1; j < arr.Length; j++)
        {
          if (arr[i] > arr[j])
          {
            int a = arr[i];
            arr[i] = arr[j];
            arr[j] = a;
          }
        }
      }
    }
  }
}
